import http from '../utils/httpRequest.js'

// 发送手机验证码
export function sendVerifyCode(params) {
    http({
        ...params,
        path: "/auth/phoneVerifyCode?phone=" + params.phone,
        testData: 600, // 600秒冷却时间,
        showLoading: true,
    })
}

let testSysUser = {
    id: 1,
    shopId: 1,
    username: "system-test",
    phone: "170581-test",
    sex: 1,
    avatar: "https://xxl-1302724632.cos.ap-shanghai.myqcloud.com/sysUserAvatar/1/QQ%E5%9B%BE%E7%89%8720210328225418.jpg",
    roleNames: "xxx管理员,xx管理员",
    token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjEsIk1lcmNoYW50SWQiOjEsImV4cCI6MTY0MTI4MTYwNn0.-EYSUswHL_V3swimde7MWS8qbxgE243ZFhz5QVM-u-4",
}

// 登录
export function login(params) {
    params.method = "POST"
    params.path = "/auth/login"
    params.testData = testSysUser
    params.showLoading = true
    http(params)
}

// 通过手机验证码登录
export function loginByPhone(params) {
    http({
        ...params,
        method: 'POST',
        path: '/auth/loginByPhone?phone=' + params.phone + "&code=" + params.code,
        testData: testSysUser,
        showLoading: true,
    })
}

// 获取当前登录的用户信息
export function getUserInfo(params) {
    http({
        ...params,
        path: '/me/userInfo',
        testData: testSysUser,
    })
}

// 修改密码
export function updatePassword(params) {
    http({
        ...params,
        method: 'PUT',
        path: '/me/updatePassword',
    })
}

// 退出登录
export function logout(params) {
    http({
        ...params,
        method: 'DELETE',
        path: "/me/logout",
    })
}
